﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkStation.Frameworks.EasyBus.Pipeline.Handles;

namespace WorkStation.Frameworks.EasyBus.Pipeline
{
    /// <summary>
    /// 处理结果
    /// </summary>
    public abstract class HandleResult
    {
        /// <summary>
        /// 提示信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 输入
        /// </summary>
        public object Input { get; set; }

        /// <summary>
        /// 处理器
        /// </summary>
        public IHandle Handle { get; set; }

        /// <summary>
        /// 附加信息
        /// </summary>
        public Dictionary<string, object> Extends { get; set; }

        protected HandleResult(object input, IHandle handle)
        {
            this.Extends = new Dictionary<string, object>();
            this.Input = input;
            this.Handle = handle;
        }
    }

    /// <summary>
    /// 成功处理结果
    /// </summary>
    public class SuccessHandleResult : HandleResult
    {
        public SuccessHandleResult(object input, IHandle handle, string message = null)
            : base(input, handle)
        {
            this.Message = message;
        }
    }

    /// <summary>
    /// 失败处理结果
    /// </summary>
    public class FailHandleResult : HandleResult
    {
        /// <summary>
        /// 异常
        /// </summary>
        public Exception Error { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorMessage { get; set; }

        public FailHandleResult(object input, IHandle handle, string errorMessage = null, Exception exception = null)
            : base(input, handle)
        {
            this.Error = exception;
            this.ErrorMessage = errorMessage;
        }
    }

    /// <summary>
    /// 重试处理结果
    /// </summary>
    public class RetryHandleResult : FailHandleResult
    {
        public int RetryCount { get; set; }

        public int CurrentRetryCount { get; set; }

        public RetryHandleResult(object input, IHandle handle, string errorMessage = null, Exception exception = null, int retryCount = -1, int currentRetryCount = 0)
            : base(input, handle, errorMessage, exception)
        {
            this.RetryCount = retryCount;
            this.CurrentRetryCount = currentRetryCount;
        }
    }
}
